using System;

namespace System.Web.Core
{
    public class RequestBuilder
    {
        private RequestBuilder()
        {
        }

        public static TRequest BuildAddEntityRequest<TRequest>(Entity entity) where TRequest : EntityRequest, new()
        {
            TRequest request = new TRequest();
            request.Operation = OperationType.Add;
            request.Entity = entity;
            return request;
        }
        public static EntityRequest BuildAddEntityRequest(EntityRequest request)
        {
            request.Operation = OperationType.Add;
            return request;
        }

        public static TRequest BuildDeleteEntityRequest<TRequest>(int entityId) where TRequest : EntityRequest, new()
        {
            TRequest request = new TRequest();
            request.Operation = OperationType.Delete;
            request.EntityId = entityId;
            return request;
        }
        public static EntityRequest BuildDeleteEntityRequest(EntityRequest request)
        {
            request.Operation = OperationType.Delete;
            return request;
        }

        public static TRequest BuildUpdateEntityRequest<TRequest>(Entity entity) where TRequest : EntityRequest, new()
        {
            TRequest request = new TRequest();
            request.Operation = OperationType.Update;
            request.Entity = entity;
            return request;
        }
        public static EntityRequest BuildUpdateEntityRequest(EntityRequest request)
        {
            request.Operation = OperationType.Update;
            return request;
        }

        public static BaseRequest BuildGetEntityListRequest<TRequest>() where TRequest : BaseRequest, new()
        {
            return BuildGetEntityListRequest(new TRequest());
        }
        public static BaseRequest BuildGetEntityListRequest(BaseRequest request)
        {
            request.Operation = OperationType.GetList;
            return request;
        }

        public static TRequest BuildGetEntityRequest<TRequest>() where TRequest : EntityRequest, new()
        {
            TRequest request = new TRequest();
            request.Operation = OperationType.Get;
            return request;
        }
        public static TRequest BuildGetEntityRequest<TRequest>(int entityId) where TRequest : EntityRequest, new()
        {
            TRequest request = new TRequest();
            request.Operation = OperationType.Get;
            request.EntityId = entityId;
            return request;
        }
        public static EntityRequest BuildGetEntityRequest(EntityRequest request)
        {
            request.Operation = OperationType.Get;
            return request;
        }
    }
}